<!doctype html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <link rel="stylesheet" href="css/common.css">
  <link rel="stylesheet" href="css/style.css">
  <link rel="stylesheet" href="css/jquery-impromptu.min.css" type="text/css"/>
    <link rel="stylesheet" href="css/jquery-ui.css"/>
    <link rel="stylesheet" href="css/jquery-impromptu.min.css" type="text/css"/>
  <title>财务系统</title>
    <style>
        a{
            color: inherit;
        }
        #confirm_section{
            color:#333;
            background:#e6e6e6 url('images/ext_btn.png');
            border:1px solid #c4c4c4;
            border-radius:2px;
            text-shadow:0 1px 1px rgba(255,255,255,.75);
            padding:4px 10px;
            display:inline-block;
            cursor:pointer;
            font-size:12px;
            line-height:normal;
            text-decoration:none;
            overflow:visible;
            vertical-align:middle;
            text-align:center;
            zoom:1;
            white-space:nowrap;
            _position:relative;margin:0
        background-position:0 -120px;
            background-color:#1b75b6;
            text-shadow:0 -1px 0 rgba(0,0,0,.25);
            border-color:#106bab #106bab #0d68a9
        }
        #confirm_section:hover{
            background-position:0 -160px
        }
    </style>
</head>

<body>
    <div class="top">
      <div id="top_t">
        <div id="logo" class="fl"></div>
        <div id="photo_info" class="fr">
          <div id="photo" class="fl">

          </div>
          <div id="base_info" class="fr">
            <div class="help_info">
              <a href="" id="hp">&nbsp;</a>
              <a href="#" id="gy">&nbsp;</a>
              <a href="login.html" id="out">&nbsp;</a>
            </div>
            <div class="info_center">
              <span id="username">admin</span>—
              <span id="exec_name">职别</span>
            </div>
          </div>
        </div>
      </div>
      <div id="side_here">
        <div id="side_here_l" class="fl"></div>
        <div id="here_area" class="fl">所属部门：
            <select name="" class="select" style="border: 1px solid #003eff" id="section_info">
            </select>
            <input type="button" value="确定" id="confirm_section">
        </div>
      </div>
    </div>
    <div class="side">
        <div class="sideMenu" style="margin:0 auto">
       </div>
    </div>
    <div class="main">
       <iframe name="right" id="rightMain" src="guide.html" frameborder="no" scrolling="auto" width="100%" height="auto" allowtransparency="true"></iframe>
    </div>
    <div class="bottom">
      <div id="bottom_bg">版权所有：宜宾市翠屏区公安局，四川敦诚科技有限责任公司&copy;2017</div>
    </div>

</body>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery-ui.js"></script>
<script type="text/javascript" src="js/jquery.SuperSlide.js"></script>
<script src="js/jquery-impromptu.min.js" type="text/javascript"></script>
<script type="text/javascript" src="js/common.js"></script>
<script type="text/javascript" src="js/config.js"></script>
<script type="text/javascript" src="js/jquery-impromptu.min.js"></script>
<script type="text/javascript">
    //辅助函数，创建用户和部门
    function createUserAndSection(data){

        if(data.sys_admin == 1){
            $('#username').html('管理员');
            $('#here_area').hide();
        }
        else{
            //设置用户名
            $("#username").html(data.user_name);
            $('#exec_name').html(data.executive_name);
            $('#here_area').show();
            //设置所属部门
            var s_info = data.department_info;
            for(var i = 0; i < s_info.length; i++){
                $('#section_info').append("<option value="+ i + ">" + s_info[i]['department_name'] + "</option>");
            }
            window.localStorage.setItem('cur_department', 0);
        }


    }

//    //辅助函数，用于判断是否为部门管理员（业务权限）
//    function isDepartmentApproveAdmin(department_id, adminInfo){
//        for(var i = 0; i < adminInfo.length; i++){
//            if(adminInfo[i].is_approve == 1 && adminInfo[i].section_id == department_id){
//                        return true;
//            }
//        }
//        return false;
//    }
//    //辅助函数，用于判断是否为部门管理员（财务权限）
//    function isDepartmentFeeAdmin(department_id, adminInfo){
//        for(var i = 0; i < adminInfo.length; i++){
//            if(adminInfo[i].is_fee == 1 && adminInfo[i].section_id == department_id){
//                return true;
//            }
//        }
//        return false;
//    }

    function createAdminMenu(){
        $('.sideMenu').append("<h3 id='admin_task'>管理员功能</h3>" +
            "<ul>" +
            "<li id='user_manage'><a href='#'>人员管理</a></li>" +
            "<li id='section_manage'><a href='#'>部门管理</a></li>" +
            "<li id='standard_manage'><a href='#'>报销标准</a></li>" +
            "<li id='auth_manage'><a href='#'>权限管理</a></li>" +
            "<li id='finance_manage'><a href='#'>财务人员管理</a></li>" +
            "<li id='admin_manage'><a href='#'>管理员管理</a></li>" +
            "</ul>");
    }

    //辅助函数，设置部门菜单
    function createDepartSideMenu(data){
        if(data.admin_power.section_fee == 1 || data.admin_power.section_approve == 1){
            //如果是部门管理员，设置部门菜单
            $('.sideMenu').append("<h3 id='section_task'>部门审批</h3>" +
                    "<ul>" +
                    "<li id='section_approve'><a href='#'>部门业务审批</a></li>" +
                    "<li id='section_fee_approve'><a href='#'>部门报销审批</a></li>" +
                    "</ul>");
            if(data.admin_power.section_fee == 0){
                $('#section_fee_approve').hide();
            }
            if(data.admin_power.section_approve == 0){
                $('#section_approve').hide();
            }
        }

    }



    function createHighLevelSideMenu(data){
        if(data.admin_power.manage_fee == 1 || data.admin_power.manage_approve == 1){
            $('.sideMenu').append("<h3 id='regular_task'>分管签批</h3>" +
                    "<ul>" +
                    "<li id='business_approve'><a href='#'>业务申请签批</a></li>" +
                    "<li id='fee_approve'><a href='#'>费用报销签批</a></li>" +
                    "</ul>");

            if(data.admin_power.manage_fee != 1){
                $('#fee_approve').hide();
            }
            if(data.admin_power.manage_approve != 1){
                $('#business_approve').hide();
            }
        }
    }

    function createLeaderSideMenu(data){
        if(data.admin_power.leader_fee == 1 || data.admin_power.leader_approve == 1){
            $('.sideMenu').append("<h3 id='regular_task'>领导审批</h3>" +
                    "<ul>" +
                    "<li id='leader_business_approve'><a href='#'>业务申请审批</a></li>" +
                    "<li id='leader_fee_approve'><a href='#'>费用报销审批</a></li>" +
                    "</ul>");
            if(data.admin_power.leader_fee != 1){
                $('#leader_fee_approve').hide();
            }
            if(data.admin_power.leader_approve != 1){
                $('#leader_business_approve').hide();
            }
        }
    }


    //辅助函数，用于创建侧边栏
    function createUserSideMenu(data){
        $('.sideMenu').empty();
        if(data.sys_admin == 1){
            createAdminMenu();
        }
        else{
            //设置基本菜单
            $('.sideMenu').append("<h3 id='regular_task'>日常业务</h3>" +
                    "<ul>" +
                    "<li id='daily01'><a href='#'>出差审批</a></li>" +
                    "<li id='daily03'><a href='#'>报销业务</a></li>" +
                    "<li id='loan_fee'><a href='#'>借款业务</a>"+
                    "</ul>");
            //设置业务菜单
            $('.sideMenu').append("<h3 id='regular_task'>我的业务</h3>" +
                    "<ul>" +
                    "<li id='my_busi_approval'><a href='#'>我的出差</a></li>" +
                    "<li id='my_fee_approval'><a href='#'>我的报销</a></li>" +
                    "<li id='my_loan'><a href='#'>我的借款</a></li>" +
                    "</ul>");
            //创建部门管理菜单
            createDepartSideMenu(data);

            //创建分管菜单
            createHighLevelSideMenu(data);

            //创建领导菜单
            createLeaderSideMenu(data);
            //如果是财务管理者，设置财务管理菜单
            if(data.finance_admin){
                $('.sideMenu').append("<h3 id='regular_task'>财务管理</h3>" +
                        "<ul>" +
                        "<li id='finance_app'><a href='#'>报销复核</a></li>" +
                        "<li id='loan_app'><a href='#'>借款核销</a></li>" +
                        "<li id='item_manage'><a href='#'>财务管理</a></li>" +
                        "<li id='finance_data'><a href='#'>财务数据</a></li>" +
                        "</ul>");
            }
        }


        $(".sideMenu").slide({
            titCell:"h3",
            targetCell:"ul",
            defaultIndex:0,
            effect:'slideDown',
            delayTime:'500' ,
            trigger:'click',
            triggerTime:'150',
            defaultPlay:true,
            returnDefault:false,
            easing:'easeInQuint',
            endFun:function(){
                scrollWW();
            }
        });

        $(window).resize(function() {
            scrollWW();
        });
        $("li").each(function(index, element){
            $(element).click(function(){
                if($(this).hasClass() != "on") {
                    $(this).addClass("on");
                }

                if($(this).attr('id') == 'daily01'){
                    $('#rightMain').attr('src', 'bussiness_approval.html');
                }
                if($(this).attr('id') == 'daily02'){
                    $('#rightMain').attr('src', 'loanMoneyConfirm.html');
                }
                if($(this).attr('id') == 'daily03'){
                    $('#rightMain').attr('src', 'feeApprovalConfirm.html');
                }
                if($(this).attr('id') == 'loan_fee'){
                    $('#rightMain').attr('src', 'loanMoneyConfirm.html');
                }

                if($(this).attr('id') == 'my_busi_approval'){
                    window.localStorage.setItem('approve_type', 0);
                    $('#rightMain').attr('src', 'my_bussiness_approval.html');
                }
                if($(this).attr('id') == 'my_fee_approval'){
                    window.localStorage.setItem('approve_type', 0);
                    $('#rightMain').attr('src', 'my_fee_apply.html');
                }
                if($(this).attr('id') == 'my_loan'){
                    window.localStorage.setItem('approve_type', 0);
                    $('#rightMain').attr('src', 'my_ordinary_loan_fee.html');
                }
                if($(this).attr('id') == 'section_approve'){
                    window.localStorage.setItem('approve_type', 1);
                    window.localStorage.setItem('is_fee', 0);
                    $('#rightMain').attr('src', 'section_approve.html');
                }
                if($(this).attr('id') == 'section_fee_approve'){
                    window.localStorage.setItem('approve_type', 1);
                    window.localStorage.setItem('is_fee', 1);
                    $('#rightMain').attr('src', 'section_approve.html');
                }
                if($(this).attr('id') == 'business_approve'){
                    window.localStorage.setItem('approve_type', 2);
                    window.localStorage.setItem('is_fee', 0);
                    $('#rightMain').attr('src', 'section_approve.html');
                }
                if($(this).attr('id') == 'fee_approve'){
                    window.localStorage.setItem('approve_type', 2);
                    window.localStorage.setItem('is_fee', 1);
                    $('#rightMain').attr('src', 'section_approve.html');
                }
                if($(this).attr('id') == 'leader_business_approve'){
                    window.localStorage.setItem('approve_type', 3);
                    window.localStorage.setItem('is_fee', 0);
                    $('#rightMain').attr('src', 'section_approve.html');
                }
                if($(this).attr('id') == 'leader_fee_approve'){
                    window.localStorage.setItem('approve_type', 3);
                    window.localStorage.setItem('is_fee', 1);
                    $('#rightMain').attr('src', 'section_approve.html');
                }
                if($(this).attr('id') == 'finance_app'){
                    $('#rightMain').attr('src', 'finance_fee_approve.html');
                }
                if($(this).attr('id') == 'loan_app'){
                    $('#rightMain').attr('src', 'finance_loan_fee_fuhe.html');
                }
                if($(this).attr('id') == 'user_manage'){
                    $('#rightMain').attr('src', './manager/usermanager.html');
                }
                if($(this).attr('id') == 'section_manage'){
                    $('#rightMain').attr('src', './manager/sectionmanager.html');
                }
                if($(this).attr('id') == 'standard_manage'){
                    $('#rightMain').attr('src', './manager/hotel_moneymanager.html');
                }
                if($(this).attr('id') == 'auth_manage'){
                    $('#rightMain').attr('src', './manager/leadermanager.html');
                }
                if($(this).attr('id') == 'admin_manage'){
                    $('#rightMain').attr('src', './manager/adminmanager.html');
                }
                if($(this).attr('id') == 'finance_manage'){
                    $('#rightMain').attr('src', './manager/financeadminmanager.html');
                }
                if($(this).attr('id') == 'item_manage'){
                    $('#rightMain').attr('src', 'finance_item_manage.html');
                }
                if($(this).attr('id') == 'finance_data'){
                    $('#rightMain').attr('src', 'finance_section_fee_manage.html');
                }
                var lis = $("li");
                for(var i = 0; i < lis.length; i++){
                    if(this != lis[i]){
                        $(lis[i]).removeClass("on");
                    }
                }
            })
        })

    }

    $(function(){

        //判断用户是否登录
        judegeLoginState();

        //读取存放在本地存储中的数据
        var data = JSON.parse(window.localStorage.getItem('user_info'));

        //创建用户和部门信息
        createUserAndSection(data);

        //创建侧边栏
        createUserSideMenu(data, 0);

        //切换部门
        $('#confirm_section').click(function(){
            window.localStorage.setItem('cur_department', $('#section_info').val());
            createUserSideMenu(data);
            //设置默认页面
            $("#rightMain").attr('src', 'guide.html');

        });

        $('#hp').click(function(){
            $("#rightMain").attr('src', 'guide.html');
        });

        $('#gy').click(function(){
            $.prompt("<h3>本系统由四川敦诚科技有限责任公司和宜宾市翠屏区公安局联合开发</h3>", {
                title: '错误提醒',
                buttons: {'确定': true}
            })
        })


        //设置默认页面
        $("#rightMain").attr('src', 'guide.html');

    });





    function scrollWW(){
        if($(".side").height()<$(".sideMenu").height()){
            $(".scroll").show();
            var pos = $(".sideMenu ul:visible").position().top-38;
            $('.sideMenu').animate({top:-pos});
        }else{
            $(".scroll").hide();
            $('.sideMenu').animate({top:0});
            n=1;
        }
    }

    var n=1;
    function menuScroll(num){
        var Scroll = $('.sideMenu');
        var ScrollP = $('.sideMenu').position();

        if(num==1){
            Scroll.animate({top:ScrollP.top-38});
            n = n+1;
        }else{
            if (ScrollP.top > -38 && ScrollP.top != 0) { ScrollP.top = -38; }
            if (ScrollP.top<0) {
                Scroll.animate({top:38+ScrollP.top});
            }else{
                n=1;
            }
            if(n>1){
                n = n-1;
            }
        }
    }
</script>

</html>
   
 